﻿using RBAC.Domain;
using RBAC.Repository.Interfae;
using RBAC.Repository.RabbitInterfae;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Traceab.DTO;
using Traceability.Domain;
using Traceability.Service.Interfae;

namespace Traceability.Service.Impl
{
    public class SlPriseService : ISlPriseService
    {
        /// <summary>
        /// 屠宰企业仓储
        /// </summary>
        private readonly ISlPriseRepository _slaughterRepository;
        /// <summary>
        /// 省份仓储
        /// </summary>
        protected readonly IProvinceRepository _provinceService;
        /// <summary>
        /// 市仓储
        /// </summary>
        protected readonly ICityRepository _cityService;
        /// <summary>
        /// 县仓储
        /// </summary>
        protected readonly ICountryRepository _countryService;
        public SlPriseService(ISlPriseRepository slaughterRepository, IProvinceRepository provinceRepository,
           ICityRepository cityRepository, ICountryRepository countryRepository )
        {
            _slaughterRepository = slaughterRepository;
            _provinceService = provinceRepository;
            _cityService = cityRepository;
            _countryService = countryRepository;
        }
        /// <summary>
        /// 添加屠宰企业信息
        /// </summary>
        /// <param name="enterPrise"></param>
        /// <returns></returns>
        public async Task<int> AddSSlPrise(SlaughterEnterPrise enterPrise)
        {
            return await _slaughterRepository.AddAsync(enterPrise);
        }
        /// <summary>
        /// 显示屠宰企业信息
        /// </summary>
        /// <param name="batch"></param>
        /// <returns></returns>
        public async Task<List<SlPriseDTO>> GetSlaughterEnterPrises(string batch)
        {
            var listobj = from a in await _slaughterRepository.GetAllAsync()
                          join b in await _provinceService.GetAllAsync()
                            on a.provinceId equals b.provinceId
                          join c in await _cityService.GetAllAsync()
                          on a.cityId equals c.cityId
                          join d in await _countryService.GetAllAsync()
                          on a.countryId equals d.countryId
                          where !a.SlaughterEnterPriseDel && a.Batch == batch
                          select new SlPriseDTO
                          {
                              provinceName = b.provinceName,
                              cityName = c.cityName,
                              countryName = d.countryName,
                              SlaughterEnterPriseId = a.SlaughterEnterPriseId,
                              SlaughterEnterPriseName = a.SlaughterEnterPriseName,
                              provinceId = a.provinceId,
                              cityId = a.cityId,
                              countryId = a.countryId,
                              CreateDate = a.CreateDate,
                              Desc = a.Desc,
                              Batch = a.Batch,
                              SlaughterEnterPriseDel = a.SlaughterEnterPriseDel

                          };
            return listobj.ToList();
        }
        /// <summary>
        /// 修改屠宰企业信息
        /// </summary>
        /// <param name="slaughterEnterPrise"></param>
        /// <returns></returns>
        public async Task<int> UpdateSlPrise(SlaughterEnterPrise slaughterEnterPrise)
        {
            return await _slaughterRepository.UpdateAsync(slaughterEnterPrise);
        }
    }
}
